package org.mspring.platform.web.freemarker.widget.http.impl;

import java.io.Serializable;
import java.util.Map;

import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;

import org.mspring.platform.web.freemarker.widget.http.HttpWidgetRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.util.WebUtils;

/**
 *
 * @author Gao Youbo
 * @since 2012-12-5
 */
public class DefaultHttpWidgetRequest extends HttpServletRequestWrapper implements HttpWidgetRequest, Serializable {

    private static final long serialVersionUID = 3897644570585254713L;

    private static final Logger log = LoggerFactory.getLogger(DefaultHttpWidgetRequest.class);

    private Map<String, ?> widgetModel;

    /**
     * @param request
     */
    public DefaultHttpWidgetRequest(HttpServletRequest request) {
        super(request);
    }

    @Override
    public Map<String, ?> getWidgetModel() {
        return widgetModel;
    }

    @Override
    public void bindWidgetModel(Map<String, ?> widgetModel) {
        this.widgetModel = widgetModel;
    }

    @Override
    public RequestDispatcher getRequestDispatcher(String path) {
        try {
            setAttribute(WebUtils.INCLUDE_PATH_INFO_ATTRIBUTE, path);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
        return super.getRequestDispatcher(path);
    }

}
